require(["config"],function(){
    require(["jquery","template","swiper","load"],function($,template){
        
        // 首页页面交互
        function homeIndexHandler() {
            this.init();
            
        };

        $.extend(homeIndexHandler.prototype,{
            // 初始化页面
            init(){
                // 加载菜单
                this.loadbannerMuen();
                //加载热卖商品
                this.loadHotProduct();
                // 加载商品类别类别信息
                this.loadProductCategory();
                const mYswiper = new Swiper('.swiper-container', {
                    pagination: '.swiper-pagination',
                    nextButton: '.swiper-button-next',
                    prevButton: '.swiper-button-prev',
                    slidesPerView: 1,
                    paginationClickable: true,
                    spaceBetween: 30,
                    autoplay: 3000,
                    loop: true
                });
                
            },
            //加载banner菜单页面数据
            loadbannerMuen(){
                $.getJSON("http://rap2api.taobao.org/app/mock/data/718613",(data) => {
                    const muenHtml = template("muen",{muenArray : data.res_body.firstMuen});
                    $(".muen")[0].innerHTML = muenHtml;
                    $(".muen-list").on("mouseover",function(){
                        var len = $(this).find("li").length;
                        $(this).find(".muen-box").css({width: len * 260 + "px"});
                    })
                })
            },
            //加载热卖商品数据
            loadHotProduct(){
                $.getJSON("http://rap2api.taobao.org/app/mock/data/719580",(data)=> {
                    const HotProductHtml = template("productHot",{productHotArray : data.res_body.hot_list});
                    $(".hot-list").html(HotProductHtml);
                })
            },
            // 加载商品类别信息
            loadProductCategory(){
                $.getJSON("http://rap2api.taobao.org/app/mock/data/719643",(data)=>{
                    const category = template("category",{productArr : data.res_body});
                    $(".product-categroy").html(category);
                })
            }
            
        });
        new homeIndexHandler();
    })
})
